local ServerOHOH = _G.ServerOHOH;
local CommonOHOH =_G.CommonOHOH
local BigNumberHelper = CommonOHOH.load.BigNumberHelper();
local GeneralTool=_G.CommonOHOH.load.GeneralTool();
local Server_RankManager = ServerOHOH.load.Server_RankManager();

local hour=60*60

function UpdRankData(key,value,userId)
	Server_RankManager:SetRankValue(key, userId, function()
		return GeneralTool.ShortRankNumber(value)
	end);
end

local RankList={
	level = CommonOHOH.load.RankUiObject().new(workspace.Rank:WaitForChild("level"),function(valueLable,value,userId)
		local newValue,HadNoTag=GeneralTool.RecoverRankNumber(value)
		valueLable.Text=BigNumberHelper:ToString(newValue)

	end),
	time=CommonOHOH.load.RankUiObject().new(workspace.Rank:WaitForChild("time"),function(valueLable,value,userId)
		local h=math.floor(value/hour)
        valueLable.Text=h.." hour"
	end),
	kill=CommonOHOH.load.RankUiObject().new(workspace.Rank:WaitForChild("kill"),function(valueLable,value,userId)

		local newValue,HadNoTag=GeneralTool.RecoverRankNumber(value)
		valueLable.Text=BigNumberHelper:ToString(newValue)
	end),
	
	sponsor=CommonOHOH.load.RankUiObject().new(workspace.Rank:WaitForChild("sponsor")),
	save=CommonOHOH.load.RankUiObject().new(workspace.Rank:WaitForChild("save")),

}

local M = ServerOHOH.class.new(script, ServerOHOH.files.BaseComponent());

function M.new(self,...)
	return M(self,...);
end;


function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.data={}

  self.UpdUiCon= _G.server:GetComponent(ServerOHOH.load.Server_RankComponent()).UpdataRankDataEvent:Connect(function(rankData)
            if rankData then
				for k,v in pairs(rankData) do
					if RankList[k] then
						RankList[k]:Update(v)
					end
				end
			end
    end)
end;

function M.dtor(self)
    self.UpdUiCon:Disconnect()
	M.super.dtor(self);
end;



return M;

